package main

import (
	"fmt"
	"sync"
)

var sum int
var wg sync.WaitGroup

func main() {
	run()
}
func run() {
	wg.Add(110) // 监控 110个携程
	for i := 0; i < 100; i++ {
		go func() {
			// 计数器值减1
			defer wg.Done()
			add(10)
		}()
		// go add(10)
	}
	for i := 0; i < 10; i++ {
		go func() {
			// 计数器值减1
			defer wg.Done()
			go fmt.Println("sum:", readSum())
		}()
	}
	wg.Wait()
	// time.Sleep(2 * time.Second)
}
func add(n int) int {
	sum += n
	return sum
}
func readSum() int {
	b := sum
	return b
}
